package sy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sy.pageModel.BaseEntity;
import sy.pageModel.DataGrid;
import sy.pageModel.Json;
import sy.service.MassageServiceI;
import sy.util.StringUtil;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by Administrator on 2016-07-20.
 */
@Controller
@RequestMapping("/messageController")
public class MassageController extends BaseController {

    @Autowired
    private MassageServiceI massageService;
    @RequestMapping("/datagrid")
    @ResponseBody
    public DataGrid datagrid(BaseEntity curr) throws Exception {
        return massageService.findMassageList(curr);
    }

    @RequestMapping("/add")
    @ResponseBody
    public Json add(BaseEntity curr, HttpSession session) {
       int rows=0;
        try {
            BaseEntity entity=massageService.addBaseEntity(curr);
            if (entity!=null) rows=1;
        } catch (Exception e) {
           rows=0;
        }
        Json js = StringUtil.findJson(rows, "添加");
        return js;
    }

    @RequestMapping("/del")
    @ResponseBody
    public Json remove(BaseEntity curr, HttpSession session) {
        int rows=0;
        try {
            BaseEntity entity=massageService.deleteBaseEntity(curr);
            if (entity!=null) rows=1;
        } catch (Exception e) {
            rows=0;
        }
        Json js = StringUtil.findJson(rows, "删除");
        return js;
    }
    @RequestMapping("/find_tm")
    @ResponseBody
    public List<BaseEntity> findTuser(String table){
        return massageService.findTuser(table);
    }

}
